package animation.wlh.com.animation_demo.basic

import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.animation.PropertyValuesHolder
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.animation.AccelerateInterpolator
import android.view.animation.AnimationSet
import animation.wlh.com.animation_demo.R
import kotlinx.android.synthetic.main.activity_property_anim.*

/**
 * Created by weilh on 2016/1/22.
 */
class PropertyAnimationAct: AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_property_anim)
        title = "属性动画"
        translate_btn.setOnClickListener {
            var anim = ObjectAnimator.ofFloat(translate_btn, "translationX", 100f, 0f)
            anim.setDuration(3000)
            anim.start()
        }

        scale_btn.setOnClickListener {
            var anim = ObjectAnimator.ofFloat(scale_btn, "scaleX", 1f, 2f, 0.5f, 1f)
            anim.setDuration(3000)
            anim.start()
        }

        alpha_btn.setOnClickListener {
            var anim = ObjectAnimator.ofFloat(alpha_btn, "alpha", 0f, 1f)
            anim.setDuration(3000)
            anim.start()
        }

        rotation_btn.setOnClickListener {
            var anim = ObjectAnimator.ofFloat(rotation_btn, "rotation", 0f, 360f)
            anim.setDuration(3000)
            anim.start()
        }

        anim_set_btn.setOnClickListener {
            var alphaAnim = ObjectAnimator.ofFloat(anim_set_btn, "alpha", 0f, 1f)
            var rotationAnim = ObjectAnimator.ofFloat(anim_set_btn, "rotation", 0f, 360f)
            alphaAnim.setDuration(3000)
            rotationAnim.setDuration(3000)
            rotationAnim.interpolator = AccelerateInterpolator()
            var anim = AnimatorSet()
            anim.playTogether(alphaAnim, rotationAnim)
            anim.start()

//            var alphaAnim = PropertyValuesHolder.ofFloat("alpha", 0f, 1f)
//            var rotationAnim = PropertyValuesHolder.ofFloat("rotation", 0f, 370f, 360f)
//            var anim = ObjectAnimator.ofPropertyValuesHolder(anim_set_btn, alphaAnim, rotationAnim)
//            anim.setDuration(3000)
//            anim.start()
        }

    }
}
